{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Imports\n",
    "\n",
    "Import all the modules and functionalities we need."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "\n",
    "# Import standard libraries.\n",
    "import os\n",
    "\n",
    "# Import third party libraries.\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import seaborn as sns\n",
    "from statsmodels.stats.multitest import multipletests\n",
    "\n",
    "# Import custom libraries/scripts.\n",
    "import annotations\n",
    "import helpers"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Loading data\n",
    "\n",
    "Fetch all our relevant data for the current analysis."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Set working contants.\n",
    "EXPERIMENTS_PATH = r'\\\\10.40.12.80\\home\\PhD\\Results\\Competition\\DL\\small_arenas\\territory\\24h_mated\\processed'\n",
    "FPS = 60\n",
    "N_MINUTES = 15\n",
    "N_FRAMES = N_MINUTES * 60 * FPS\n",
    "INK = 'black'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Set figure configurations.\n",
    "sns.set(\n",
    "        context='paper',\n",
    "        style='ticks',\n",
    "        font='sans-serif',\n",
    "        font_scale=1.0, \n",
    "        rc={\n",
    "            'axes.axisbelow': True,\n",
    "            'axes.edgecolor': INK,\n",
    "            'axes.facecolor': 'white' if INK=='black' else 'black',\n",
    "            'axes.grid': False,\n",
    "            'axes.labelcolor': INK,\n",
    "            'axes.labelsize': 13.0,\n",
    "            'axes.labelweight': 'normal',\n",
    "            'axes.linewidth': 1.0,\n",
    "            'axes.spines.left': True,\n",
    "            'axes.spines.bottom': True,\n",
    "            'axes.spines.top': False,\n",
    "            'axes.spines.right': False,\n",
    "            'axes.titlepad': 15.0,\n",
    "            'axes.titlesize': 20.0,\n",
    "            'axes.titleweight': 'bold',\n",
    "            'figure.facecolor': 'white' if INK=='black' else 'black',\n",
    "            'figure.figsize': [6.0, 4.0],\n",
    "            'figure.titlesize': 30.0,\n",
    "            'figure.titleweight': 'bold',\n",
    "            'font.family': ['sans-serif'],\n",
    "            'font.sans-serif': ['Arial'],\n",
    "            'legend.frameon': False,\n",
    "            'legend.fontsize': 11.0,\n",
    "            'lines.color': INK,\n",
    "            'lines.linewidth': 1.0,\n",
    "            'patch.edgecolor': INK,\n",
    "            'savefig.dpi': 300,\n",
    "            'savefig.format': 'png',\n",
    "            'savefig.bbox': 'tight',\n",
    "            'savefig.transparent': True,\n",
    "            'text.color': INK,\n",
    "            'text.usetex': False,\n",
    "            'xtick.color': INK,\n",
    "            'xtick.direction': 'out',\n",
    "            'xtick.labelsize': 12.0,\n",
    "            'xtick.major.pad': 5.0,\n",
    "            'xtick.major.size': 0.0,\n",
    "            'xtick.major.width': 1.0,\n",
    "            'xtick.minor.size': 0.0,\n",
    "            'xtick.minor.width': 0.4,\n",
    "            'ytick.color': INK,\n",
    "            'ytick.direction': 'out',\n",
    "            'ytick.labelsize': 12.0,\n",
    "            'ytick.major.pad': 5.0,\n",
    "            'ytick.major.size': 3.0,\n",
    "            'ytick.major.width': 1.0,\n",
    "            'ytick.minor.size': 0.0,\n",
    "            'ytick.minor.width': 0.4\n",
    "           }\n",
    "       )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Folder already exists, skipping.\n"
     ]
    }
   ],
   "source": [
    "# Prepare the Figures folder to save our graphs in.\n",
    "savepath = os.path.join(r'C:\\Users\\Miguel\\Desktop\\paper_data', 'paper_figures', 'figureS3')\n",
    "try:\n",
    "    os.makedirs(savepath)\n",
    "    print('New folder created.')\n",
    "except FileExistsError:\n",
    "    print('Folder already exists, skipping.')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Paths to conditions:\n",
      " ['\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\24h_mated\\\\processed\\\\food_odor', '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\24h_mated\\\\processed\\\\nothing']\n"
     ]
    }
   ],
   "source": [
    "# Set the conditions to analyze.\n",
    "condition_order = ['food_odor', 'nothing']\n",
    "conditions = [item.path for item in os.scandir(EXPERIMENTS_PATH) if item.name in condition_order]\n",
    "print('Paths to conditions:\\n', conditions)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\t\n",
      " food_odor\n",
      "\t\n",
      " nothing\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'food_odor': ['\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\24h_mated\\\\processed\\\\food_odor\\\\video_2022-05-25T12_07_57_arena16.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\24h_mated\\\\processed\\\\food_odor\\\\video_2022-06-08T10_59_11_arena2.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\24h_mated\\\\processed\\\\food_odor\\\\video_2022-06-08T10_59_11_arena5.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\24h_mated\\\\processed\\\\food_odor\\\\video_2022-06-08T10_59_11_arena7.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\24h_mated\\\\processed\\\\food_odor\\\\video_2022-06-08T11_21_49_arena11.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\24h_mated\\\\processed\\\\food_odor\\\\video_2022-06-08T11_21_49_arena12.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\24h_mated\\\\processed\\\\food_odor\\\\video_2022-06-08T11_21_49_arena14.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\24h_mated\\\\processed\\\\food_odor\\\\video_2022-06-08T11_50_31_arena11.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\24h_mated\\\\processed\\\\food_odor\\\\video_2022-06-08T11_50_31_arena16.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\24h_mated\\\\processed\\\\food_odor\\\\video_2022-06-09T12_04_14_arena11.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\24h_mated\\\\processed\\\\food_odor\\\\video_2022-06-09T12_04_14_arena12.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\24h_mated\\\\processed\\\\food_odor\\\\video_2022-06-09T12_04_14_arena3.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\24h_mated\\\\processed\\\\food_odor\\\\video_2022-06-09T12_04_14_arena4.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\24h_mated\\\\processed\\\\food_odor\\\\video_2022-06-09T12_04_14_arena8.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\24h_mated\\\\processed\\\\food_odor\\\\video_2022-06-09T12_35_55_arena13.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\24h_mated\\\\processed\\\\food_odor\\\\video_2022-06-09T12_35_55_arena14.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\24h_mated\\\\processed\\\\food_odor\\\\video_2022-06-09T12_35_55_arena6.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\24h_mated\\\\processed\\\\food_odor\\\\video_2022-06-09T12_35_55_arena9.csv'],\n",
       " 'nothing': ['\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\24h_mated\\\\processed\\\\nothing\\\\video_2022-05-25T11_34_25_arena16.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\24h_mated\\\\processed\\\\nothing\\\\video_2022-05-25T12_07_57_arena8.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\24h_mated\\\\processed\\\\nothing\\\\video_2022-06-08T10_59_11_arena16.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\24h_mated\\\\processed\\\\nothing\\\\video_2022-06-08T10_59_11_arena4.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\24h_mated\\\\processed\\\\nothing\\\\video_2022-06-08T10_59_11_arena8.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\24h_mated\\\\processed\\\\nothing\\\\video_2022-06-08T11_21_49_arena13.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\24h_mated\\\\processed\\\\nothing\\\\video_2022-06-08T11_21_49_arena5.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\24h_mated\\\\processed\\\\nothing\\\\video_2022-06-08T11_21_49_arena9.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\24h_mated\\\\processed\\\\nothing\\\\video_2022-06-08T11_50_31_arena14.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\24h_mated\\\\processed\\\\nothing\\\\video_2022-06-08T11_50_31_arena15.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\24h_mated\\\\processed\\\\nothing\\\\video_2022-06-08T11_50_31_arena3.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\24h_mated\\\\processed\\\\nothing\\\\video_2022-06-09T12_04_14_arena13.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\24h_mated\\\\processed\\\\nothing\\\\video_2022-06-09T12_04_14_arena15.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\24h_mated\\\\processed\\\\nothing\\\\video_2022-06-09T12_35_55_arena3.csv']}"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Load all usable experiments for each condition.\n",
    "experiments = {condition: [] for condition in condition_order}\n",
    "\n",
    "for condition_path in conditions:\n",
    "    \n",
    "    condition = os.path.basename(condition_path)\n",
    "    print('\\t\\n', condition)\n",
    "    \n",
    "    for item in os.scandir(condition_path):\n",
    "        if item.name.endswith('.csv'):\n",
    "            \n",
    "            annotation_video = annotations.read(item.path)\n",
    "            \n",
    "            experiments[condition].append(item.path)\n",
    "\n",
    "experiments"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Aggression Analysis"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Iteration: 0 \n",
      "Experiment: video_2022-05-25T12_07_57_arena16 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 1 \n",
      "Experiment: video_2022-06-08T10_59_11_arena2 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 2 \n",
      "Experiment: video_2022-06-08T10_59_11_arena5 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 3 \n",
      "Experiment: video_2022-06-08T10_59_11_arena7 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 4 \n",
      "Experiment: video_2022-06-08T11_21_49_arena11 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 5 \n",
      "Experiment: video_2022-06-08T11_21_49_arena12 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 6 \n",
      "Experiment: video_2022-06-08T11_21_49_arena14 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 7 \n",
      "Experiment: video_2022-06-08T11_50_31_arena11 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 8 \n",
      "Experiment: video_2022-06-08T11_50_31_arena16 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 9 \n",
      "Experiment: video_2022-06-09T12_04_14_arena11 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 10 \n",
      "Experiment: video_2022-06-09T12_04_14_arena12 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 11 \n",
      "Experiment: video_2022-06-09T12_04_14_arena3 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 12 \n",
      "Experiment: video_2022-06-09T12_04_14_arena4 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 13 \n",
      "Experiment: video_2022-06-09T12_04_14_arena8 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 14 \n",
      "Experiment: video_2022-06-09T12_35_55_arena13 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 15 \n",
      "Experiment: video_2022-06-09T12_35_55_arena14 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 16 \n",
      "Experiment: video_2022-06-09T12_35_55_arena6 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 17 \n",
      "Experiment: video_2022-06-09T12_35_55_arena9 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 0 \n",
      "Experiment: video_2022-05-25T11_34_25_arena16 \n",
      "Condition: nothing \n",
      "\n",
      "Iteration: 1 \n",
      "Experiment: video_2022-05-25T12_07_57_arena8 \n",
      "Condition: nothing \n",
      "\n",
      "Iteration: 2 \n",
      "Experiment: video_2022-06-08T10_59_11_arena16 \n",
      "Condition: nothing \n",
      "\n",
      "Iteration: 3 \n",
      "Experiment: video_2022-06-08T10_59_11_arena4 \n",
      "Condition: nothing \n",
      "\n",
      "Iteration: 4 \n",
      "Experiment: video_2022-06-08T10_59_11_arena8 \n",
      "Condition: nothing \n",
      "\n",
      "Iteration: 5 \n",
      "Experiment: video_2022-06-08T11_21_49_arena13 \n",
      "Condition: nothing \n",
      "\n",
      "Iteration: 6 \n",
      "Experiment: video_2022-06-08T11_21_49_arena5 \n",
      "Condition: nothing \n",
      "\n",
      "Iteration: 7 \n",
      "Experiment: video_2022-06-08T11_21_49_arena9 \n",
      "Condition: nothing \n",
      "\n",
      "Iteration: 8 \n",
      "Experiment: video_2022-06-08T11_50_31_arena14 \n",
      "Condition: nothing \n",
      "\n",
      "Iteration: 9 \n",
      "Experiment: video_2022-06-08T11_50_31_arena15 \n",
      "Condition: nothing \n",
      "\n",
      "Iteration: 10 \n",
      "Experiment: video_2022-06-08T11_50_31_arena3 \n",
      "Condition: nothing \n",
      "\n",
      "Iteration: 11 \n",
      "Experiment: video_2022-06-09T12_04_14_arena13 \n",
      "Condition: nothing \n",
      "\n",
      "Iteration: 12 \n",
      "Experiment: video_2022-06-09T12_04_14_arena15 \n",
      "Condition: nothing \n",
      "\n",
      "Iteration: 13 \n",
      "Experiment: video_2022-06-09T12_35_55_arena3 \n",
      "Condition: nothing \n",
      "\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>has_aggression</th>\n",
       "      <th>ratio_frames</th>\n",
       "      <th>ratio_bouts</th>\n",
       "      <th>condition</th>\n",
       "      <th>experiment</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>True</td>\n",
       "      <td>0.004278</td>\n",
       "      <td>0.2</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-05-25T12_07_57_arena16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>True</td>\n",
       "      <td>0.002722</td>\n",
       "      <td>0.6</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-08T10_59_11_arena2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>True</td>\n",
       "      <td>0.003611</td>\n",
       "      <td>0.4</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-08T10_59_11_arena5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>True</td>\n",
       "      <td>0.005278</td>\n",
       "      <td>1.0</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-08T10_59_11_arena7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>True</td>\n",
       "      <td>0.007667</td>\n",
       "      <td>1.0</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-08T11_21_49_arena11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>True</td>\n",
       "      <td>0.001333</td>\n",
       "      <td>0.2</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-08T11_21_49_arena12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>True</td>\n",
       "      <td>0.008556</td>\n",
       "      <td>1.2</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-08T11_21_49_arena14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>True</td>\n",
       "      <td>0.002222</td>\n",
       "      <td>0.4</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-08T11_50_31_arena11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>True</td>\n",
       "      <td>0.000222</td>\n",
       "      <td>0.2</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-08T11_50_31_arena16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>True</td>\n",
       "      <td>0.002889</td>\n",
       "      <td>1.2</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-09T12_04_14_arena11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>True</td>\n",
       "      <td>0.045056</td>\n",
       "      <td>1.2</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-09T12_04_14_arena12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>True</td>\n",
       "      <td>0.021111</td>\n",
       "      <td>2.2</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-09T12_04_14_arena3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>True</td>\n",
       "      <td>0.010889</td>\n",
       "      <td>1.6</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-09T12_04_14_arena4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>True</td>\n",
       "      <td>0.008167</td>\n",
       "      <td>1.0</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-09T12_04_14_arena8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>True</td>\n",
       "      <td>0.001167</td>\n",
       "      <td>0.8</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-09T12_35_55_arena13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>True</td>\n",
       "      <td>0.009278</td>\n",
       "      <td>1.0</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-09T12_35_55_arena14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>True</td>\n",
       "      <td>0.010222</td>\n",
       "      <td>1.4</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-09T12_35_55_arena6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>True</td>\n",
       "      <td>0.008500</td>\n",
       "      <td>1.0</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-09T12_35_55_arena9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>False</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>nothing</td>\n",
       "      <td>video_2022-05-25T11_34_25_arena16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>True</td>\n",
       "      <td>0.000944</td>\n",
       "      <td>0.4</td>\n",
       "      <td>nothing</td>\n",
       "      <td>video_2022-05-25T12_07_57_arena8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>False</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>nothing</td>\n",
       "      <td>video_2022-06-08T10_59_11_arena16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>True</td>\n",
       "      <td>0.005333</td>\n",
       "      <td>1.0</td>\n",
       "      <td>nothing</td>\n",
       "      <td>video_2022-06-08T10_59_11_arena4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>True</td>\n",
       "      <td>0.001333</td>\n",
       "      <td>0.4</td>\n",
       "      <td>nothing</td>\n",
       "      <td>video_2022-06-08T10_59_11_arena8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>False</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>nothing</td>\n",
       "      <td>video_2022-06-08T11_21_49_arena13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>True</td>\n",
       "      <td>0.005167</td>\n",
       "      <td>0.4</td>\n",
       "      <td>nothing</td>\n",
       "      <td>video_2022-06-08T11_21_49_arena5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>True</td>\n",
       "      <td>0.002500</td>\n",
       "      <td>0.4</td>\n",
       "      <td>nothing</td>\n",
       "      <td>video_2022-06-08T11_21_49_arena9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>True</td>\n",
       "      <td>0.000889</td>\n",
       "      <td>0.4</td>\n",
       "      <td>nothing</td>\n",
       "      <td>video_2022-06-08T11_50_31_arena14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>True</td>\n",
       "      <td>0.002667</td>\n",
       "      <td>0.6</td>\n",
       "      <td>nothing</td>\n",
       "      <td>video_2022-06-08T11_50_31_arena15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>False</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>nothing</td>\n",
       "      <td>video_2022-06-08T11_50_31_arena3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>True</td>\n",
       "      <td>0.000333</td>\n",
       "      <td>0.2</td>\n",
       "      <td>nothing</td>\n",
       "      <td>video_2022-06-09T12_04_14_arena13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>True</td>\n",
       "      <td>0.007889</td>\n",
       "      <td>1.2</td>\n",
       "      <td>nothing</td>\n",
       "      <td>video_2022-06-09T12_04_14_arena15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>True</td>\n",
       "      <td>0.004278</td>\n",
       "      <td>0.6</td>\n",
       "      <td>nothing</td>\n",
       "      <td>video_2022-06-09T12_35_55_arena3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    has_aggression  ratio_frames  ratio_bouts  condition  \\\n",
       "0             True      0.004278          0.2  food_odor   \n",
       "1             True      0.002722          0.6  food_odor   \n",
       "2             True      0.003611          0.4  food_odor   \n",
       "3             True      0.005278          1.0  food_odor   \n",
       "4             True      0.007667          1.0  food_odor   \n",
       "5             True      0.001333          0.2  food_odor   \n",
       "6             True      0.008556          1.2  food_odor   \n",
       "7             True      0.002222          0.4  food_odor   \n",
       "8             True      0.000222          0.2  food_odor   \n",
       "9             True      0.002889          1.2  food_odor   \n",
       "10            True      0.045056          1.2  food_odor   \n",
       "11            True      0.021111          2.2  food_odor   \n",
       "12            True      0.010889          1.6  food_odor   \n",
       "13            True      0.008167          1.0  food_odor   \n",
       "14            True      0.001167          0.8  food_odor   \n",
       "15            True      0.009278          1.0  food_odor   \n",
       "16            True      0.010222          1.4  food_odor   \n",
       "17            True      0.008500          1.0  food_odor   \n",
       "18           False      0.000000          0.0    nothing   \n",
       "19            True      0.000944          0.4    nothing   \n",
       "20           False      0.000000          0.0    nothing   \n",
       "21            True      0.005333          1.0    nothing   \n",
       "22            True      0.001333          0.4    nothing   \n",
       "23           False      0.000000          0.0    nothing   \n",
       "24            True      0.005167          0.4    nothing   \n",
       "25            True      0.002500          0.4    nothing   \n",
       "26            True      0.000889          0.4    nothing   \n",
       "27            True      0.002667          0.6    nothing   \n",
       "28           False      0.000000          0.0    nothing   \n",
       "29            True      0.000333          0.2    nothing   \n",
       "30            True      0.007889          1.2    nothing   \n",
       "31            True      0.004278          0.6    nothing   \n",
       "\n",
       "                           experiment  \n",
       "0   video_2022-05-25T12_07_57_arena16  \n",
       "1    video_2022-06-08T10_59_11_arena2  \n",
       "2    video_2022-06-08T10_59_11_arena5  \n",
       "3    video_2022-06-08T10_59_11_arena7  \n",
       "4   video_2022-06-08T11_21_49_arena11  \n",
       "5   video_2022-06-08T11_21_49_arena12  \n",
       "6   video_2022-06-08T11_21_49_arena14  \n",
       "7   video_2022-06-08T11_50_31_arena11  \n",
       "8   video_2022-06-08T11_50_31_arena16  \n",
       "9   video_2022-06-09T12_04_14_arena11  \n",
       "10  video_2022-06-09T12_04_14_arena12  \n",
       "11   video_2022-06-09T12_04_14_arena3  \n",
       "12   video_2022-06-09T12_04_14_arena4  \n",
       "13   video_2022-06-09T12_04_14_arena8  \n",
       "14  video_2022-06-09T12_35_55_arena13  \n",
       "15  video_2022-06-09T12_35_55_arena14  \n",
       "16   video_2022-06-09T12_35_55_arena6  \n",
       "17   video_2022-06-09T12_35_55_arena9  \n",
       "18  video_2022-05-25T11_34_25_arena16  \n",
       "19   video_2022-05-25T12_07_57_arena8  \n",
       "20  video_2022-06-08T10_59_11_arena16  \n",
       "21   video_2022-06-08T10_59_11_arena4  \n",
       "22   video_2022-06-08T10_59_11_arena8  \n",
       "23  video_2022-06-08T11_21_49_arena13  \n",
       "24   video_2022-06-08T11_21_49_arena5  \n",
       "25   video_2022-06-08T11_21_49_arena9  \n",
       "26  video_2022-06-08T11_50_31_arena14  \n",
       "27  video_2022-06-08T11_50_31_arena15  \n",
       "28   video_2022-06-08T11_50_31_arena3  \n",
       "29  video_2022-06-09T12_04_14_arena13  \n",
       "30  video_2022-06-09T12_04_14_arena15  \n",
       "31   video_2022-06-09T12_35_55_arena3  "
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "aggression_df = pd.DataFrame()\n",
    "for condition in experiments.keys():\n",
    "    for h, experiment_path in enumerate(experiments[condition]):\n",
    "\n",
    "        experiment = os.path.basename(experiment_path).split('.')[0]\n",
    "        \n",
    "        print('Iteration:', h, '\\nExperiment:', experiment, '\\nCondition:', condition, '\\n')\n",
    "        \n",
    "        annotation_video = annotations.read(experiment_path)\n",
    "        aggression_events = annotation_video[1].events\n",
    "        n_events = len(aggression_events)\n",
    "\n",
    "        # In case there is aggression, do the necessary calculations.\n",
    "        if n_events > 0:\n",
    "            \n",
    "            ratio_frames = sum([aggression.duration for aggression in aggression_events]) / (5 * 60 * FPS)\n",
    "            ratio_bouts = n_events / 5\n",
    "            \n",
    "            aggression_data = pd.DataFrame({'has_aggression': True,\n",
    "                                            'ratio_frames': ratio_frames,\n",
    "                                            'ratio_bouts': ratio_bouts,\n",
    "                                            'condition': condition,\n",
    "                                            'experiment': experiment},\n",
    "                                            index=[h],\n",
    "                                           )\n",
    "\n",
    "        # If not, preset our dictionary with default values.\n",
    "        else:\n",
    "            aggression_data = pd.DataFrame({'has_aggression': False,\n",
    "                                            'ratio_frames': 0, \n",
    "                                            'ratio_bouts': 0,\n",
    "                                            'condition': condition,\n",
    "                                            'experiment': experiment},\n",
    "                                            index=[h],\n",
    "                                           )\n",
    "\n",
    "        # Concatenate all data together.\n",
    "        aggression_df = pd.concat([aggression_df, aggression_data], ignore_index=True)\n",
    "\n",
    "aggression_df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Outlier Detection"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\t food_odor \n",
      "\n",
      "[10]\n",
      "Number data points considered outliers: 1\n",
      "Percent data points considered outliers: 5.556 %\n",
      "\n",
      "\t nothing \n",
      "\n",
      "[]\n",
      "Number data points considered outliers: 0\n",
      "Percent data points considered outliers: 0.0 %\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>has_aggression</th>\n",
       "      <th>ratio_frames</th>\n",
       "      <th>ratio_bouts</th>\n",
       "      <th>condition</th>\n",
       "      <th>experiment</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>True</td>\n",
       "      <td>0.004278</td>\n",
       "      <td>0.2</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-05-25T12_07_57_arena16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>True</td>\n",
       "      <td>0.002722</td>\n",
       "      <td>0.6</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-08T10_59_11_arena2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>True</td>\n",
       "      <td>0.003611</td>\n",
       "      <td>0.4</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-08T10_59_11_arena5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>True</td>\n",
       "      <td>0.005278</td>\n",
       "      <td>1.0</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-08T10_59_11_arena7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>True</td>\n",
       "      <td>0.007667</td>\n",
       "      <td>1.0</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-08T11_21_49_arena11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>True</td>\n",
       "      <td>0.001333</td>\n",
       "      <td>0.2</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-08T11_21_49_arena12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>True</td>\n",
       "      <td>0.008556</td>\n",
       "      <td>1.2</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-08T11_21_49_arena14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>True</td>\n",
       "      <td>0.002222</td>\n",
       "      <td>0.4</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-08T11_50_31_arena11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>True</td>\n",
       "      <td>0.000222</td>\n",
       "      <td>0.2</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-08T11_50_31_arena16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>True</td>\n",
       "      <td>0.002889</td>\n",
       "      <td>1.2</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-09T12_04_14_arena11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>True</td>\n",
       "      <td>0.021111</td>\n",
       "      <td>2.2</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-09T12_04_14_arena3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>True</td>\n",
       "      <td>0.010889</td>\n",
       "      <td>1.6</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-09T12_04_14_arena4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>True</td>\n",
       "      <td>0.008167</td>\n",
       "      <td>1.0</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-09T12_04_14_arena8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>True</td>\n",
       "      <td>0.001167</td>\n",
       "      <td>0.8</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-09T12_35_55_arena13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>True</td>\n",
       "      <td>0.009278</td>\n",
       "      <td>1.0</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-09T12_35_55_arena14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>True</td>\n",
       "      <td>0.010222</td>\n",
       "      <td>1.4</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-09T12_35_55_arena6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>True</td>\n",
       "      <td>0.008500</td>\n",
       "      <td>1.0</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-09T12_35_55_arena9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>False</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>nothing</td>\n",
       "      <td>video_2022-05-25T11_34_25_arena16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>True</td>\n",
       "      <td>0.000944</td>\n",
       "      <td>0.4</td>\n",
       "      <td>nothing</td>\n",
       "      <td>video_2022-05-25T12_07_57_arena8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>False</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>nothing</td>\n",
       "      <td>video_2022-06-08T10_59_11_arena16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>True</td>\n",
       "      <td>0.005333</td>\n",
       "      <td>1.0</td>\n",
       "      <td>nothing</td>\n",
       "      <td>video_2022-06-08T10_59_11_arena4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>True</td>\n",
       "      <td>0.001333</td>\n",
       "      <td>0.4</td>\n",
       "      <td>nothing</td>\n",
       "      <td>video_2022-06-08T10_59_11_arena8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>False</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>nothing</td>\n",
       "      <td>video_2022-06-08T11_21_49_arena13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>True</td>\n",
       "      <td>0.005167</td>\n",
       "      <td>0.4</td>\n",
       "      <td>nothing</td>\n",
       "      <td>video_2022-06-08T11_21_49_arena5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>True</td>\n",
       "      <td>0.002500</td>\n",
       "      <td>0.4</td>\n",
       "      <td>nothing</td>\n",
       "      <td>video_2022-06-08T11_21_49_arena9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>True</td>\n",
       "      <td>0.000889</td>\n",
       "      <td>0.4</td>\n",
       "      <td>nothing</td>\n",
       "      <td>video_2022-06-08T11_50_31_arena14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>True</td>\n",
       "      <td>0.002667</td>\n",
       "      <td>0.6</td>\n",
       "      <td>nothing</td>\n",
       "      <td>video_2022-06-08T11_50_31_arena15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>False</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>nothing</td>\n",
       "      <td>video_2022-06-08T11_50_31_arena3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>True</td>\n",
       "      <td>0.000333</td>\n",
       "      <td>0.2</td>\n",
       "      <td>nothing</td>\n",
       "      <td>video_2022-06-09T12_04_14_arena13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>True</td>\n",
       "      <td>0.007889</td>\n",
       "      <td>1.2</td>\n",
       "      <td>nothing</td>\n",
       "      <td>video_2022-06-09T12_04_14_arena15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>True</td>\n",
       "      <td>0.004278</td>\n",
       "      <td>0.6</td>\n",
       "      <td>nothing</td>\n",
       "      <td>video_2022-06-09T12_35_55_arena3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    has_aggression  ratio_frames  ratio_bouts  condition  \\\n",
       "0             True      0.004278          0.2  food_odor   \n",
       "1             True      0.002722          0.6  food_odor   \n",
       "2             True      0.003611          0.4  food_odor   \n",
       "3             True      0.005278          1.0  food_odor   \n",
       "4             True      0.007667          1.0  food_odor   \n",
       "5             True      0.001333          0.2  food_odor   \n",
       "6             True      0.008556          1.2  food_odor   \n",
       "7             True      0.002222          0.4  food_odor   \n",
       "8             True      0.000222          0.2  food_odor   \n",
       "9             True      0.002889          1.2  food_odor   \n",
       "11            True      0.021111          2.2  food_odor   \n",
       "12            True      0.010889          1.6  food_odor   \n",
       "13            True      0.008167          1.0  food_odor   \n",
       "14            True      0.001167          0.8  food_odor   \n",
       "15            True      0.009278          1.0  food_odor   \n",
       "16            True      0.010222          1.4  food_odor   \n",
       "17            True      0.008500          1.0  food_odor   \n",
       "18           False      0.000000          0.0    nothing   \n",
       "19            True      0.000944          0.4    nothing   \n",
       "20           False      0.000000          0.0    nothing   \n",
       "21            True      0.005333          1.0    nothing   \n",
       "22            True      0.001333          0.4    nothing   \n",
       "23           False      0.000000          0.0    nothing   \n",
       "24            True      0.005167          0.4    nothing   \n",
       "25            True      0.002500          0.4    nothing   \n",
       "26            True      0.000889          0.4    nothing   \n",
       "27            True      0.002667          0.6    nothing   \n",
       "28           False      0.000000          0.0    nothing   \n",
       "29            True      0.000333          0.2    nothing   \n",
       "30            True      0.007889          1.2    nothing   \n",
       "31            True      0.004278          0.6    nothing   \n",
       "\n",
       "                           experiment  \n",
       "0   video_2022-05-25T12_07_57_arena16  \n",
       "1    video_2022-06-08T10_59_11_arena2  \n",
       "2    video_2022-06-08T10_59_11_arena5  \n",
       "3    video_2022-06-08T10_59_11_arena7  \n",
       "4   video_2022-06-08T11_21_49_arena11  \n",
       "5   video_2022-06-08T11_21_49_arena12  \n",
       "6   video_2022-06-08T11_21_49_arena14  \n",
       "7   video_2022-06-08T11_50_31_arena11  \n",
       "8   video_2022-06-08T11_50_31_arena16  \n",
       "9   video_2022-06-09T12_04_14_arena11  \n",
       "11   video_2022-06-09T12_04_14_arena3  \n",
       "12   video_2022-06-09T12_04_14_arena4  \n",
       "13   video_2022-06-09T12_04_14_arena8  \n",
       "14  video_2022-06-09T12_35_55_arena13  \n",
       "15  video_2022-06-09T12_35_55_arena14  \n",
       "16   video_2022-06-09T12_35_55_arena6  \n",
       "17   video_2022-06-09T12_35_55_arena9  \n",
       "18  video_2022-05-25T11_34_25_arena16  \n",
       "19   video_2022-05-25T12_07_57_arena8  \n",
       "20  video_2022-06-08T10_59_11_arena16  \n",
       "21   video_2022-06-08T10_59_11_arena4  \n",
       "22   video_2022-06-08T10_59_11_arena8  \n",
       "23  video_2022-06-08T11_21_49_arena13  \n",
       "24   video_2022-06-08T11_21_49_arena5  \n",
       "25   video_2022-06-08T11_21_49_arena9  \n",
       "26  video_2022-06-08T11_50_31_arena14  \n",
       "27  video_2022-06-08T11_50_31_arena15  \n",
       "28   video_2022-06-08T11_50_31_arena3  \n",
       "29  video_2022-06-09T12_04_14_arena13  \n",
       "30  video_2022-06-09T12_04_14_arena15  \n",
       "31   video_2022-06-09T12_35_55_arena3  "
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "corrected_ratio_frames = pd.DataFrame()\n",
    "\n",
    "for condition in condition_order:\n",
    "\n",
    "    print('\\n\\t', condition, '\\n')\n",
    "\n",
    "    try:\n",
    "        dataset = aggression_df.query('condition==\"' + condition + '\"')['ratio_frames']\n",
    "\n",
    "        outlier_positions = helpers.check_outliers(dataset)\n",
    "        print(outlier_positions)\n",
    "\n",
    "        fresh_dataset = pd.DataFrame(helpers.remove_outliers(dataset, indices=outlier_positions))\n",
    "        fresh_dataset['condition'] = condition\n",
    "\n",
    "        corrected_ratio_frames = pd.concat([corrected_ratio_frames, fresh_dataset], axis=0)\n",
    "        \n",
    "    except ValueError as error:\n",
    "        print(error)\n",
    "\n",
    "aggression_df = aggression_df.loc[corrected_ratio_frames.index]\n",
    "aggression_df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Amount of Aggressive Bouts / Minute"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>condition</th>\n",
       "      <th>ratio_bouts</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>food_odor</td>\n",
       "      <td>0.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>food_odor</td>\n",
       "      <td>0.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>food_odor</td>\n",
       "      <td>0.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>food_odor</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>food_odor</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>food_odor</td>\n",
       "      <td>0.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>food_odor</td>\n",
       "      <td>1.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>food_odor</td>\n",
       "      <td>0.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>food_odor</td>\n",
       "      <td>0.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>food_odor</td>\n",
       "      <td>1.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>food_odor</td>\n",
       "      <td>2.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>food_odor</td>\n",
       "      <td>1.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>food_odor</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>food_odor</td>\n",
       "      <td>0.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>food_odor</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>food_odor</td>\n",
       "      <td>1.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>food_odor</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>nothing</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>nothing</td>\n",
       "      <td>0.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>nothing</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>nothing</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>nothing</td>\n",
       "      <td>0.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>nothing</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>nothing</td>\n",
       "      <td>0.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>nothing</td>\n",
       "      <td>0.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>nothing</td>\n",
       "      <td>0.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>nothing</td>\n",
       "      <td>0.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>nothing</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>nothing</td>\n",
       "      <td>0.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>nothing</td>\n",
       "      <td>1.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>nothing</td>\n",
       "      <td>0.6</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    condition  ratio_bouts\n",
       "0   food_odor          0.2\n",
       "1   food_odor          0.6\n",
       "2   food_odor          0.4\n",
       "3   food_odor          1.0\n",
       "4   food_odor          1.0\n",
       "5   food_odor          0.2\n",
       "6   food_odor          1.2\n",
       "7   food_odor          0.4\n",
       "8   food_odor          0.2\n",
       "9   food_odor          1.2\n",
       "11  food_odor          2.2\n",
       "12  food_odor          1.6\n",
       "13  food_odor          1.0\n",
       "14  food_odor          0.8\n",
       "15  food_odor          1.0\n",
       "16  food_odor          1.4\n",
       "17  food_odor          1.0\n",
       "18    nothing          0.0\n",
       "19    nothing          0.4\n",
       "20    nothing          0.0\n",
       "21    nothing          1.0\n",
       "22    nothing          0.4\n",
       "23    nothing          0.0\n",
       "24    nothing          0.4\n",
       "25    nothing          0.4\n",
       "26    nothing          0.4\n",
       "27    nothing          0.6\n",
       "28    nothing          0.0\n",
       "29    nothing          0.2\n",
       "30    nothing          1.2\n",
       "31    nothing          0.6"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ratio_bouts_df = aggression_df.copy()\n",
    "ratio_bouts_df = ratio_bouts_df[['condition', 'ratio_bouts']]\n",
    "ratio_bouts_df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Statistics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\t nothing \n",
      "\n",
      "Shapiro's Test: group 1 IS normally distributed.\n",
      "D'Agostino's Test: group 1 IS normally distributed.\n",
      "Shapiro's Test: group 2 IS normally distributed.\n",
      "D'Agostino's Test: group 2 IS normally distributed.\n",
      "Bartlett's Test for normally distribted samples:\n",
      "  p-value = 0.156368\n",
      "  All groups were sampled from populations with IDENTICAL variances.\n",
      "\n",
      "Independent measures (two sample) t-test p-value: 0.006027527897115673 \n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\program files\\python37\\lib\\site-packages\\scipy\\stats\\stats.py:1535: UserWarning: kurtosistest only valid for n>=20 ... continuing anyway, n=17\n",
      "  \"anyway, n=%i\" % int(n))\n",
      "c:\\program files\\python37\\lib\\site-packages\\scipy\\stats\\stats.py:1535: UserWarning: kurtosistest only valid for n>=20 ... continuing anyway, n=14\n",
      "  \"anyway, n=%i\" % int(n))\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'nothing': 0.006027527897115673}"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ratio_bouts_pvalues = {}\n",
    "\n",
    "control = ratio_bouts_df.query('condition==\"food_odor\"')['ratio_bouts']\n",
    "\n",
    "for condition in condition_order[1:]:\n",
    "        \n",
    "    print('\\n\\t', condition, '\\n')\n",
    "\n",
    "    try:\n",
    "        test = ratio_bouts_df.query('condition==\"' + condition + '\"')['ratio_bouts']\n",
    "\n",
    "        temp_values = {'control': control, 'test': test}\n",
    "\n",
    "        pvalue_condition = helpers.run_statistics(temp_values)\n",
    "\n",
    "        ratio_bouts_pvalues[condition] = pvalue_condition\n",
    "        \n",
    "    except ValueError as error:\n",
    "        print(error)\n",
    "\n",
    "ratio_bouts_pvalues"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Effect Size"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "nothing\n",
      "Medium Effect: -0.6 \n",
      "\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'nothing': -0.6}"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ratio_bouts_effect_sizes = {}\n",
    "\n",
    "control = ratio_bouts_df.query('condition==\"food_odor\"')['ratio_bouts']\n",
    "\n",
    "for condition in condition_order[1:]:\n",
    "    \n",
    "    print(condition)\n",
    "    \n",
    "    test = ratio_bouts_df.query('condition==\"' + condition + '\"')['ratio_bouts']\n",
    "\n",
    "    median_diff = helpers.get_effect_size(control, test, method='median_diff')\n",
    "    \n",
    "    ratio_bouts_effect_sizes[condition] = median_diff\n",
    "    \n",
    "ratio_bouts_effect_sizes"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Plot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAALgAAAFHCAYAAAASgIa/AAAABHN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XLpz73JTk5mcLCQlxdXbXv9/HHH5OWlgbAzp07adiwIRMmTMDNzY133nnnnvUx9cEslxE8e/YsgwcPZtKkSXz88cfaX9DmzZuJj4+nSZMmQOU67RYWFly9epWffvqp1te8s4bjHXfWelQoFPfN88knnxATE0N8fDxOTk6oVCq2bNlS7WM9PT0ZP368ds14qPxjdXNz4+zZs6SlpaFWq7WLq6alpeHt7X3fDJ6enrzzzjssWrRIu+369et4e3uTlZWl933x9PTE29u7yh9QZmYmQgjKy8uJj49nw4YNCCE4ceIEI0eOpHPnzkyYMOG+GerC7FrwzMxMBg8ezJw5c/jkk0+qtHZr166lqKiI/Px88vPzmThxIm+++eZ9i/thFRYWYmNjg42NDcXFxcydOxelUqltsWxtbSksLAQqDxnu2rWLgwcPIoTg2LFjBAcH8/vvv9OjRw9cXFwIDw9HqVSyd+9eDhw4oFOGKVOmsG7dOs6ePYsQgm3bthEYGEhKSope9+WObt26YWdnx9KlS1GpVKSmpjJgwAA+++wzFAoFEyZM4IsvvgAqlx9XKBS4ubnVKYsuzK7Av/zyS7Kzs/nwww+1XQp7e3vef/99o2V6++23sbKyokmTJrRp04aysjJ69OjBlStXAJg4cSKLFy/mlVdeoU2bNnz33XfMmzcPJycnXnzxRT755BP69++PtbU1u3fv5siRI7i4uLB48WKGDh2qU4ZevXrxySefMHnyZBwdHfnggw/YsmUL/v7+et2XO+7O6uHhwZNPPkm/fv2YP38+NjY2/PDDD6xevRpHR0dCQ0OZNWsWYWFhdcqiC7kQrGTWzK4Fl6S7yQKXzJoscMmsyQKXzJoscMmsyQKXzJoscMmsyQKXzNr/B0IqFsrNd30nAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 180x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Initialize figure.\n",
    "n_conditions = ratio_bouts_df['condition'].nunique()\n",
    "figure, axis = plt.subplots(figsize=(1.25*n_conditions, 4))\n",
    "\n",
    "# Draw the boxplot.\n",
    "sns.boxplot(x='condition',\n",
    "            y='ratio_bouts',\n",
    "            data=ratio_bouts_df,\n",
    "            order=condition_order,\n",
    "            palette=['steelblue', '#5e6472'],\n",
    "            width=0.6,\n",
    "            showfliers=False,\n",
    "            boxprops={'edgecolor': INK},\n",
    "            medianprops={'color': INK},\n",
    "            whiskerprops={'color': INK},\n",
    "            capprops={'color': INK}\n",
    "           )\n",
    "\n",
    "# Draw the swarmplot.\n",
    "sns.swarmplot(x='condition',\n",
    "              y='ratio_bouts',\n",
    "              data=ratio_bouts_df,\n",
    "              order=condition_order,\n",
    "              palette=['steelblue', '#5e6472'],\n",
    "              linewidth=0.75,\n",
    "              edgecolor=INK\n",
    "             )\n",
    "\n",
    "# Figure and axes formatting.\n",
    "axis.set_xlabel('24h-mated females', labelpad=75)\n",
    "axis.set_xticklabels([''])\n",
    "axis.set_ylabel('# Bouts / Minute of Copulation')\n",
    "axis.set_ylim(0, 3)\n",
    "axis.set_yticks(range(0, 3+1, 1))\n",
    "axis.set_yticklabels(range(0, 3+1, 1))\n",
    "\n",
    "# Table definition.\n",
    "row1 = [str(ratio_bouts_df.query('condition==\"'+condition+'\"').shape[0]) for condition in condition_order]\n",
    "row2 = ['Food\\nodour', 'Without\\nFood odour']\n",
    "cell_text = np.array([row1, row2])\n",
    "\n",
    "row_labels = ['n =', '']\n",
    "summary_table = axis.table(cellText= cell_text,\n",
    "                           cellLoc='center',\n",
    "                           rowLabels=row_labels,\n",
    "                           rowLoc='center',\n",
    "                           colLoc='center'\n",
    "                          )\n",
    "\n",
    "summary_table.auto_set_font_size(False)\n",
    "summary_table.set_fontsize(11)\n",
    "\n",
    "properties = summary_table.properties()\n",
    "table_cells = properties['children']\n",
    "for cell in table_cells:\n",
    "    cell.set_height(0.12)\n",
    "    cell.set_alpha(0)\n",
    "    \n",
    "# Draw statistical results.\n",
    "for p, condition in enumerate(condition_order[1:]):\n",
    "    sig_height = 6 if (ratio_bouts_pvalues.get(condition, 'NaN') == 'NaN') or (ratio_bouts_pvalues.get(condition, 'NaN') >= 0.05) else 2\n",
    "    helpers.plot_stattest_result(ax=axis,\n",
    "                                 x1=p+1,\n",
    "                                 x2=p+1,\n",
    "                                 p_value=ratio_bouts_pvalues.get(condition, 'NaN'),\n",
    "                                 y=2.7,\n",
    "                                 ticksize=0,\n",
    "                                 xytext=(0,sig_height),\n",
    "                                 fontsize=13,\n",
    "                                 color=INK,\n",
    "                                 connector_color=INK\n",
    "                                )\n",
    "\n",
    "# Saving parameters.\n",
    "filename = 'nbouts_aggression_normalized_5mins_territory_24h_mated'\n",
    "plt.savefig( os.path.join(savepath, filename))\n",
    "\n",
    "plt.show()\n",
    "plt.close()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Attack Headings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Iteration: 0 \n",
      "Experiment: video_2022-05-25T12_07_57_arena16 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 1 \n",
      "Experiment: video_2022-06-08T10_59_11_arena2 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 2 \n",
      "Experiment: video_2022-06-08T10_59_11_arena5 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 3 \n",
      "Experiment: video_2022-06-08T10_59_11_arena7 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 4 \n",
      "Experiment: video_2022-06-08T11_21_49_arena11 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 5 \n",
      "Experiment: video_2022-06-08T11_21_49_arena12 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 6 \n",
      "Experiment: video_2022-06-08T11_21_49_arena14 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 7 \n",
      "Experiment: video_2022-06-08T11_50_31_arena11 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 8 \n",
      "Experiment: video_2022-06-08T11_50_31_arena16 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 9 \n",
      "Experiment: video_2022-06-09T12_04_14_arena11 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 10 \n",
      "Experiment: video_2022-06-09T12_04_14_arena12 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 11 \n",
      "Experiment: video_2022-06-09T12_04_14_arena3 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 12 \n",
      "Experiment: video_2022-06-09T12_04_14_arena4 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 13 \n",
      "Experiment: video_2022-06-09T12_04_14_arena8 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 14 \n",
      "Experiment: video_2022-06-09T12_35_55_arena13 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 15 \n",
      "Experiment: video_2022-06-09T12_35_55_arena14 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 16 \n",
      "Experiment: video_2022-06-09T12_35_55_arena6 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 17 \n",
      "Experiment: video_2022-06-09T12_35_55_arena9 \n",
      "Condition: food_odor \n",
      "\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>has_aggression</th>\n",
       "      <th>ratio_frames</th>\n",
       "      <th>n_heads</th>\n",
       "      <th>n_flanks</th>\n",
       "      <th>condition</th>\n",
       "      <th>experiment</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>True</td>\n",
       "      <td>0.004278</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-05-25T12_07_57_arena16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>True</td>\n",
       "      <td>0.002722</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-08T10_59_11_arena2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>True</td>\n",
       "      <td>0.003611</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-08T10_59_11_arena5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>True</td>\n",
       "      <td>0.005278</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-08T10_59_11_arena7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>True</td>\n",
       "      <td>0.007667</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-08T11_21_49_arena11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>True</td>\n",
       "      <td>0.001333</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-08T11_21_49_arena12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>True</td>\n",
       "      <td>0.008556</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-08T11_21_49_arena14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>True</td>\n",
       "      <td>0.002222</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-08T11_50_31_arena11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>True</td>\n",
       "      <td>0.000222</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-08T11_50_31_arena16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>True</td>\n",
       "      <td>0.002889</td>\n",
       "      <td>1</td>\n",
       "      <td>5</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-09T12_04_14_arena11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>True</td>\n",
       "      <td>0.045056</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-09T12_04_14_arena12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>True</td>\n",
       "      <td>0.021111</td>\n",
       "      <td>6</td>\n",
       "      <td>5</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-09T12_04_14_arena3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>True</td>\n",
       "      <td>0.010889</td>\n",
       "      <td>6</td>\n",
       "      <td>2</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-09T12_04_14_arena4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>True</td>\n",
       "      <td>0.008167</td>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-09T12_04_14_arena8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>True</td>\n",
       "      <td>0.001167</td>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-09T12_35_55_arena13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>True</td>\n",
       "      <td>0.009278</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-09T12_35_55_arena14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>True</td>\n",
       "      <td>0.010222</td>\n",
       "      <td>4</td>\n",
       "      <td>3</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-09T12_35_55_arena6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>True</td>\n",
       "      <td>0.008500</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-09T12_35_55_arena9</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    has_aggression  ratio_frames  n_heads  n_flanks  condition  \\\n",
       "0             True      0.004278        0         1  food_odor   \n",
       "1             True      0.002722        1         2  food_odor   \n",
       "2             True      0.003611        1         1  food_odor   \n",
       "3             True      0.005278        1         4  food_odor   \n",
       "4             True      0.007667        2         3  food_odor   \n",
       "5             True      0.001333        0         1  food_odor   \n",
       "6             True      0.008556        2         4  food_odor   \n",
       "7             True      0.002222        1         1  food_odor   \n",
       "8             True      0.000222        0         1  food_odor   \n",
       "9             True      0.002889        1         5  food_odor   \n",
       "10            True      0.045056        6         0  food_odor   \n",
       "11            True      0.021111        6         5  food_odor   \n",
       "12            True      0.010889        6         2  food_odor   \n",
       "13            True      0.008167        0         5  food_odor   \n",
       "14            True      0.001167        0         4  food_odor   \n",
       "15            True      0.009278        1         4  food_odor   \n",
       "16            True      0.010222        4         3  food_odor   \n",
       "17            True      0.008500        1         4  food_odor   \n",
       "\n",
       "                           experiment  \n",
       "0   video_2022-05-25T12_07_57_arena16  \n",
       "1    video_2022-06-08T10_59_11_arena2  \n",
       "2    video_2022-06-08T10_59_11_arena5  \n",
       "3    video_2022-06-08T10_59_11_arena7  \n",
       "4   video_2022-06-08T11_21_49_arena11  \n",
       "5   video_2022-06-08T11_21_49_arena12  \n",
       "6   video_2022-06-08T11_21_49_arena14  \n",
       "7   video_2022-06-08T11_50_31_arena11  \n",
       "8   video_2022-06-08T11_50_31_arena16  \n",
       "9   video_2022-06-09T12_04_14_arena11  \n",
       "10  video_2022-06-09T12_04_14_arena12  \n",
       "11   video_2022-06-09T12_04_14_arena3  \n",
       "12   video_2022-06-09T12_04_14_arena4  \n",
       "13   video_2022-06-09T12_04_14_arena8  \n",
       "14  video_2022-06-09T12_35_55_arena13  \n",
       "15  video_2022-06-09T12_35_55_arena14  \n",
       "16   video_2022-06-09T12_35_55_arena6  \n",
       "17   video_2022-06-09T12_35_55_arena9  "
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "aggression_df = pd.DataFrame()\n",
    "for condition in experiments.keys():\n",
    "    for h, experiment_path in enumerate(experiments[condition]):\n",
    "\n",
    "        experiment = os.path.basename(experiment_path).split('.')[0]\n",
    "        \n",
    "        print('Iteration:', h, '\\nExperiment:', experiment, '\\nCondition:', condition, '\\n')\n",
    "        \n",
    "        # Exclude experiments without copulation (since aggression is only observed during copulation).\n",
    "        annotation_video = annotations.read(experiment_path)\n",
    "        aggression_events = annotation_video[1].events\n",
    "        n_events = len(aggression_events)\n",
    "\n",
    "        # In case there is aggression, do the necessary calculations.\n",
    "        if n_events > 0:\n",
    "            \n",
    "            ratio_frames = sum([event.duration for event in aggression_events]) / (5 * 60 * FPS)\n",
    "            n_heads = [event.comment for event in aggression_events].count('head')\n",
    "            n_flanks = [event.comment for event in aggression_events].count('flank')\n",
    "            \n",
    "            aggression_data = pd.DataFrame({'has_aggression': True,\n",
    "                                            'ratio_frames': ratio_frames,\n",
    "                                            'n_heads': n_heads,\n",
    "                                            'n_flanks': n_flanks,\n",
    "                                            'condition': condition,\n",
    "                                            'experiment': experiment},\n",
    "                                            index=[h],\n",
    "                                           )\n",
    "\n",
    "        # If not, preset our dictionary with default values.\n",
    "        else:\n",
    "            aggression_data = pd.DataFrame({'has_aggression': False,\n",
    "                                            'ratio_frames': 0,\n",
    "                                            'n_heads': 0, \n",
    "                                            'n_flanks': 0,\n",
    "                                            'condition': condition,\n",
    "                                            'experiment': experiment},\n",
    "                                            index=[h],\n",
    "                                           )\n",
    "\n",
    "        # Concatenate all data together.\n",
    "        aggression_df = pd.concat([aggression_df, aggression_data], ignore_index=True)\n",
    "\n",
    "aggression_df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Outlier Detection"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\t food_odor \n",
      "\n",
      "[10]\n",
      "Number data points considered outliers: 1\n",
      "Percent data points considered outliers: 5.556 %\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>has_aggression</th>\n",
       "      <th>ratio_frames</th>\n",
       "      <th>n_heads</th>\n",
       "      <th>n_flanks</th>\n",
       "      <th>condition</th>\n",
       "      <th>experiment</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>True</td>\n",
       "      <td>0.004278</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-05-25T12_07_57_arena16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>True</td>\n",
       "      <td>0.002722</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-08T10_59_11_arena2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>True</td>\n",
       "      <td>0.003611</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-08T10_59_11_arena5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>True</td>\n",
       "      <td>0.005278</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-08T10_59_11_arena7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>True</td>\n",
       "      <td>0.007667</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-08T11_21_49_arena11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>True</td>\n",
       "      <td>0.001333</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-08T11_21_49_arena12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>True</td>\n",
       "      <td>0.008556</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-08T11_21_49_arena14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>True</td>\n",
       "      <td>0.002222</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-08T11_50_31_arena11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>True</td>\n",
       "      <td>0.000222</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-08T11_50_31_arena16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>True</td>\n",
       "      <td>0.002889</td>\n",
       "      <td>1</td>\n",
       "      <td>5</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-09T12_04_14_arena11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>True</td>\n",
       "      <td>0.021111</td>\n",
       "      <td>6</td>\n",
       "      <td>5</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-09T12_04_14_arena3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>True</td>\n",
       "      <td>0.010889</td>\n",
       "      <td>6</td>\n",
       "      <td>2</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-09T12_04_14_arena4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>True</td>\n",
       "      <td>0.008167</td>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-09T12_04_14_arena8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>True</td>\n",
       "      <td>0.001167</td>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-09T12_35_55_arena13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>True</td>\n",
       "      <td>0.009278</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-09T12_35_55_arena14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>True</td>\n",
       "      <td>0.010222</td>\n",
       "      <td>4</td>\n",
       "      <td>3</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-09T12_35_55_arena6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>True</td>\n",
       "      <td>0.008500</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-06-09T12_35_55_arena9</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    has_aggression  ratio_frames  n_heads  n_flanks  condition  \\\n",
       "0             True      0.004278        0         1  food_odor   \n",
       "1             True      0.002722        1         2  food_odor   \n",
       "2             True      0.003611        1         1  food_odor   \n",
       "3             True      0.005278        1         4  food_odor   \n",
       "4             True      0.007667        2         3  food_odor   \n",
       "5             True      0.001333        0         1  food_odor   \n",
       "6             True      0.008556        2         4  food_odor   \n",
       "7             True      0.002222        1         1  food_odor   \n",
       "8             True      0.000222        0         1  food_odor   \n",
       "9             True      0.002889        1         5  food_odor   \n",
       "11            True      0.021111        6         5  food_odor   \n",
       "12            True      0.010889        6         2  food_odor   \n",
       "13            True      0.008167        0         5  food_odor   \n",
       "14            True      0.001167        0         4  food_odor   \n",
       "15            True      0.009278        1         4  food_odor   \n",
       "16            True      0.010222        4         3  food_odor   \n",
       "17            True      0.008500        1         4  food_odor   \n",
       "\n",
       "                           experiment  \n",
       "0   video_2022-05-25T12_07_57_arena16  \n",
       "1    video_2022-06-08T10_59_11_arena2  \n",
       "2    video_2022-06-08T10_59_11_arena5  \n",
       "3    video_2022-06-08T10_59_11_arena7  \n",
       "4   video_2022-06-08T11_21_49_arena11  \n",
       "5   video_2022-06-08T11_21_49_arena12  \n",
       "6   video_2022-06-08T11_21_49_arena14  \n",
       "7   video_2022-06-08T11_50_31_arena11  \n",
       "8   video_2022-06-08T11_50_31_arena16  \n",
       "9   video_2022-06-09T12_04_14_arena11  \n",
       "11   video_2022-06-09T12_04_14_arena3  \n",
       "12   video_2022-06-09T12_04_14_arena4  \n",
       "13   video_2022-06-09T12_04_14_arena8  \n",
       "14  video_2022-06-09T12_35_55_arena13  \n",
       "15  video_2022-06-09T12_35_55_arena14  \n",
       "16   video_2022-06-09T12_35_55_arena6  \n",
       "17   video_2022-06-09T12_35_55_arena9  "
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "corrected_ratio_frames = pd.DataFrame()\n",
    "\n",
    "for condition in condition_order:\n",
    "\n",
    "    print('\\n\\t', condition, '\\n')\n",
    "\n",
    "    try:\n",
    "        dataset = aggression_df.query('condition==\"' + condition + '\"')['ratio_frames']\n",
    "\n",
    "        outlier_positions = helpers.check_outliers(dataset)\n",
    "        print(outlier_positions)\n",
    "\n",
    "        fresh_dataset = pd.DataFrame(helpers.remove_outliers(dataset, indices=outlier_positions))\n",
    "        fresh_dataset['condition'] = condition\n",
    "\n",
    "        corrected_ratio_frames = pd.concat([corrected_ratio_frames, fresh_dataset], axis=0)\n",
    "        \n",
    "    except ValueError as error:\n",
    "        print(error)\n",
    "\n",
    "aggression_df = aggression_df.loc[corrected_ratio_frames.index]\n",
    "aggression_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>condition</th>\n",
       "      <th>n_heads</th>\n",
       "      <th>n_flanks</th>\n",
       "      <th>proportion_heads</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>food_odor</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>food_odor</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>0.33</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>food_odor</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0.50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>food_odor</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>0.20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>food_odor</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>0.40</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   condition  n_heads  n_flanks  proportion_heads\n",
       "0  food_odor        0         1              0.00\n",
       "1  food_odor        1         2              0.33\n",
       "2  food_odor        1         1              0.50\n",
       "3  food_odor        1         4              0.20\n",
       "4  food_odor        2         3              0.40"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "headings_df = aggression_df.copy()[['condition', 'n_heads', 'n_flanks']]\n",
    "headings_df['proportion_heads'] = round(headings_df['n_heads'] / (headings_df['n_heads'] + headings_df['n_flanks']), 2)\n",
    "#headings_df['proportion_heads'].fillna(0, inplace=True)\n",
    "headings_df.dropna(inplace=True)\n",
    "headings_df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Plot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAHkAAAEgCAYAAACQDNzCAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+j8jraAAAepklEQVR4nO2de1jMaf/H36OpkEMph0npvEoHU5LkoeS0IeW0Itbp+TnEOq/js1vsXjlc7GPRLtYhlOOiRQ5ZEY8nKUnOIUmKdKBJKTNz//5ozWOk6R7Nd6Z27td1zXXpO/P9ft/jPZ/7/t6nz80jhBAw/tY00rQABvcwk7UAZrIWwEzWApjJWgAzWQtQi8nz589Hhw4dIBQKIRQKMWrUKEgkEsyZMwf29vawtbXF5s2b1SFFOyFqwNPTk1y+fFnuWEREBPHz8yPv3r0jRUVFpGPHjiQpKUkdcrQOziO5oqIC169fx5o1a+Ds7Izhw4cjOzsbR48excSJE8Hn82FkZISgoCBERUVxLUcr4dzk3Nxc+Pr64scff0R6ejo8PT0REBCA7OxsmJubyz5nZmaGnJwcruVoJZybbGVlhZMnT8LJyQk8Hg8LFizAo0ePkJmZCR6PJ/scIQQ6Ojo1XicsLAw8Hk/2YtDDucnp6enYs2eP3DFCCLy9vZGbmys7lpubCzMzsxqvExYWBkIICOtqVxrOTW7UqBFmzZqFx48fAwB+/fVXuLi4ICAgADt27IBYLMarV6+wf/9+BAYGci1HK+FzfQMnJyds3LgR/v7+kEgkMDMzw759+2BqaopHjx6hc+fOqKysxNSpU+Ht7c21HK2ERyjKv4cPHyIyMhIJCQnIycmBjo4OzMzM0LdvX4wePRo2Njbq0CqDx+OxYlsJFJpcWFiIOXPmICEhAQEBAXB3d4dAIIBYLEZeXh6SkpJw6tQp+Pr6Yt26dTAxMVGPaGaycihqRHt7e5Njx44RqVRa42fEY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eXl7q/RIfwIprSj7eYZYQArFYXOPxj+eu8fmaiydmMiW+vr6yiM3MzMTly5fRvXt3ueMFBQWIiYmBj48P+vbti+joaEilUjx58gT//e9/NaadFdeUbNiwAVOmTMHOnTvB4/Gwbds2CAQCfP/99wgJCYGzszMkEgmWLVsGNzc3ODs749atW3BwcICFhQWcnJw0pp3N8dICWHGtBTCTtQBmshbATP6L0tJSzJgxA7a2tujcuTN69uyJc+fOVftcVlYWLC0t1S+wDjCT8b99NvT09HDnzh3cuHEDGzZswLhx4zQ2qKBSNLaesh5x/vx5YmVlRaRSqdzxiIgI4uvrS1JTU4mrqytxdXUlEyZMIBYWFoQQQp4/f04GDRpEnJ2diaurKzl16hQhhJDQ0FASGhoqu877pa47d+4kPj4+xMnJiSxZskRdX0/9i9DrI8nJyXB3d6+W7rBXr15ITk7G119/jdWrVyM1NRXW1tay97/55hv4+voiPT0dv//+OyZNmoQXL14ovFdOTg6uX7+O8PBwTr7Lp2Amo2r5rFgsrna8srISEokEubm56NevHwBgwoQJsvfj4+Nl+2V92J+tCDc3N7V3cTKTUbUeOiUlBe/evZM7npiYCA8Pjxr7oGn7rT+8bpMmTVQtv1aYyQB69uwJR0dHzJkzR2bItWvX8OOPPyI0NBQWFhaIjY0FAOzdu1d2Xk392SYmJrh9+zaAqm0O8/Ly1PyN5GEm/8WRI0egr68PJycndOrUCbNnz0ZUVBR8fHwQFRWF5cuXw9XVFY8ePZKds2HDBsTHx8PZ2RmBgYGy/uygoCAUFRWhU6dO2LhxI1xdXTX4zVjftVbAIlkLYCZrAcxkLYCZrAUwk7UAZrIWwEzWApjJWgAzWQtgJmsB/w+Tte3Ti3uwQgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 90x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Initialize figure.\n",
    "n_conditions = headings_df['condition'].nunique()\n",
    "figure, axis = plt.subplots(figsize=(1.25*n_conditions, 4))\n",
    "\n",
    "# Draw the boxplot.\n",
    "sns.barplot(x='condition',\n",
    "            y='proportion_heads',\n",
    "            data=headings_df,\n",
    "            order=condition_order,\n",
    "            palette=['steelblue'],\n",
    "            ci=95,\n",
    "            n_boot=1000,\n",
    "            errcolor=INK,\n",
    "            edgecolor=INK\n",
    "           )\n",
    "\n",
    "# Format barplot grouping colors and hatching.\n",
    "for barplot in axis.patches:\n",
    "    bar_x = barplot.get_x()\n",
    "    bar_width = barplot.get_width()\n",
    "\n",
    "    new_width = 0.5\n",
    "    new_x = bar_x + (bar_width - new_width) / 2\n",
    "\n",
    "    barplot.set_width(new_width)\n",
    "    barplot.set_x(new_x)\n",
    "\n",
    "# Figure and axes formatting.\n",
    "axis.set_xlabel('')\n",
    "axis.set_xticklabels([''])\n",
    "axis.set_ylabel('Proportion Head-to-Head Strikes (%)')\n",
    "axis.set_ylim(0, 0.5)\n",
    "axis.set_yticks(np.arange(0, 0.5+0.001, 0.1))\n",
    "axis.set_yticklabels([int(y*100) for y in axis.get_yticks()])\n",
    "\n",
    "# Table definition.\n",
    "row1 = [str(headings_df.query('condition==\"'+condition+'\"').shape[0]) for condition in condition_order]\n",
    "row2 = ['Food\\nOdour']\n",
    "cell_text = np.array([row1, row2])\n",
    "\n",
    "row_labels = ['n =', '']\n",
    "summary_table = axis.table(cellText= cell_text,\n",
    "                           cellLoc='center',\n",
    "                           rowLabels=row_labels,\n",
    "                           rowLoc='center',\n",
    "                           colLoc='center'\n",
    "                          )\n",
    "\n",
    "summary_table.auto_set_font_size(False)\n",
    "summary_table.set_fontsize(11)\n",
    "\n",
    "properties = summary_table.properties()\n",
    "table_cells = properties['children']\n",
    "for cell in table_cells:\n",
    "    cell.set_height(0.12)\n",
    "    cell.set_alpha(0)\n",
    "\n",
    "# Saving parameters.\n",
    "filename = 'proportion_head_strikes_5mins_territory_24h_mated'\n",
    "plt.savefig(os.path.join(savepath, filename))\n",
    "\n",
    "plt.show()\n",
    "plt.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
